package my.jieh.tips.util.regex;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Blueimp</p>
 * @author jieh
 * @version 1.0
 */
import java.util.regex.*;

public class GroupDemo1 {
  static final String stringlist[] = {
    "abc 123 def 456",
    "456 ghi",
    "jkl789mno"
  };

  public static void main(String args[]) {

    // compile regular expression pattern for a
    // number consisting of one or more digits

    Pattern patt = Pattern.compile("(\\d+)");

    for (
        int i = 0; i < stringlist.length; i++) {
      String currstr = stringlist[i];

      // see if the current string has a match

      Matcher match = patt.matcher(currstr);

      // if a match, print the string text
      // for the matching group (group 1)

      if (match.find()) {
        System.out.println("For \"" +
                           currstr + "\" match is: " +
                           match.group(1));
      }
    }
  }
}
